<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

$vyear=date("Y");


if (!isset($_SESSION['months1']))
	$_SESSION['months1']=date("m");
if (!isset($_SESSION['years1']))
	$_SESSION['years1']=date("Y");
	

if(isset($_REQUEST['months'])){
	$_SESSION['months1']=$_REQUEST['months'];
}
if(isset($_REQUEST['years'])){
	$_SESSION['years1']=$_REQUEST['years'];
}



if(isset($_REQUEST['prev'])){
		$m=$_REQUEST['months']-1;
		if($m<1){
			$_SESSION['months1']=12;
			$_SESSION['years1']=$_REQUEST['years']-1;
		}else $_SESSION['months1']=$_REQUEST['months']-1;
}

if(isset($_REQUEST['next'])){
		$m=$_REQUEST['months']+1;
		if($m>12){
		$_SESSION['months1']=1;
		$_SESSION['years1']=$_REQUEST['years']+1;
		}else $_SESSION['months1']=$_REQUEST['months']+1;
}


define('ADAY',(60*60*24));
$datearray = getdate();
$month = intval($_SESSION['months1']);
//$month=4;
$year = intval($_SESSION['years1']);
//$year=2012;
$mday=$datearray['mday'];
//$mday=21;
$start= mktime(0,0,0,$month,1,$year);
$firstdayarray = getdate($start);

$nmonth=date('m');
if($lang=='EN'){
$months = Array('January','February','March','April','May','June','July','August','September','October','November','December');
$days = Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
}
if($lang=='VN'){
$months = Array('Tháng Một','Tháng Hai','Tháng Ba','Tháng Tư','Tháng Năm','Tháng Sáu','Tháng Bảy','Tháng Tám','Tháng Chín','Tháng Mười','Tháng Mười Một','Tháng Mười Hai');
$days = Array('Chủ Nhật','Thứ Hai','Thứ Ba','Thứ Tư','Thứ Năm','Thứ Sáu','Thứ Bảy');
}
if($lang=='KR'){
$months = Array('1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월');
$days = Array('일','월','화','수','목','금','토');
}

$mang=array();
$dem=1;
$sqlcalendar=mysql_query("SELECT * FROM calendar c WHERE c.employee=".$id_employee." AND MONTH(c.date)='$month' AND YEAR(c.date)='$year';");
while ($row = mysql_fetch_array($sqlcalendar)){
$mang[]=array($row['id'],$row['name'],$row['date'],$row['isDelete'],$row['content']);
if($row['isDelete']==0)
	$dem++;
}


$_SESSION['listCalendar']=$mang;
include 'popup/popup_loadlistCalendar.php';
include 'popup/popup_loadCalendar.php';
?>
<script type="text/javascript">
window.onload = function(){
	for(var i=1;i<=<?=$dem?>;i++){
		new JsDatePick({
			useMode:2,
			target:"date"+i,
			dateFormat:"%Y-%m-%d"
		});
	}
};
function UpdateCalendar(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											  window.location.assign("calendar.php")
										  }
									  }
	xmlhttp.open("GET","content_calendar/UpdateCalendar.php",true);
	
	xmlhttp.send();

}
function LoadCalendar(date){
	
	document.getElementById("tilte").innerHTML="Lich lam viec " +date;
	document.getElementById("date").value=date;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("Calendar1").innerHTML=xmlhttp.responseText;
										    	popup_window_show('#sample2', { pos : 'window-center', width : '530px', height:'800px'});
										  }
									  }
	xmlhttp.open("GET","content_calendar/LoadCalendar.php?date="+date,true);
	xmlhttp.send();
	
	
}
function addCalendar2(){
	var date=document.getElementById("date").value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("Calendar1").innerHTML=xmlhttp.responseText;
										    	
										  }
									  }
	xmlhttp.open("GET","content_calendar/addCalendar2.php?date="+date,true);
	
	xmlhttp.send();

}
function delCalendar2(idCalendar){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("Calendar1").innerHTML=xmlhttp.responseText;
										    	
										  }
									  }
	xmlhttp.open("GET","content_calendar/delCalendar2.php?idCalendar="+idCalendar,true);
	xmlhttp.send();

}
function chnameCalendar2(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_calendar/chnameCalendar2.php?nameCalendar="+encodeURIComponent(str)+"&id="+id,true);
	
	xmlhttp.send();
}
function chcontentCalendar2(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_calendar/chcontentCalendar2.php?contentCalendar="+encodeURIComponent(str)+"&id="+id,true);
	
	xmlhttp.send();
}
function LoadlistCalendar(){
		
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
											  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											    	document.getElementById("Calendar").innerHTML=xmlhttp.responseText;
											    	var countmang1=document.getElementById("countmang1").value;
											    	for(var i=1;i<=countmang1;i++){
											    		new JsDatePick({
											    			useMode:2,
											    			target:"date"+i,
											    			dateFormat:"%Y-%m-%d"
											    		});
											    	}
											  }
										  }
		xmlhttp.open("GET","content_calendar/LoadlistCalendar.php?month="+<?=$month?>+"&year="+<?=$_SESSION['years1']?>,true);
		xmlhttp.send();
}
function delCalendar1(idCalendar){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("Calendar").innerHTML=xmlhttp.responseText;
										    	var countmang1=document.getElementById("countmang1").value;
										    	
										    	for(var i=1;i<=countmang1;i++){
										    		new JsDatePick({
										    			useMode:2,
										    			target:"date"+i,
										    			dateFormat:"%Y-%m-%d"
										    		});
										    	}
										  }
									  }
	xmlhttp.open("GET","content_calendar/delCalendar.php?idCalendar="+idCalendar,true);
	xmlhttp.send();

}
function addCalendar1(){

	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("Calendar").innerHTML=xmlhttp.responseText;
										    	var countmang1=document.getElementById("countmang1").value;
										    	for(var i=1;i<=countmang1;i++){
										    		new JsDatePick({
										    			useMode:2,
										    			target:"date"+i,
										    			dateFormat:"%Y-%m-%d"
										    		});
										    	}
										  }
									  }
	xmlhttp.open("GET","content_calendar/addCalendar.php?month="+<?=$month?>+"&year="+<?=$year?>,true);
	
	xmlhttp.send();

}
function chnameCalendar(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_calendar/chnameCalendar.php?nameCalendar="+encodeURIComponent(str)+"&id="+id,true);
	
	xmlhttp.send();
}
function chdateStart(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											
										  }
									  }
	xmlhttp.open("GET","content_calendar/chdateStart.php?dateStart="+str+"&id="+id,true);
	xmlhttp.send();
}
function chcontentCalendar(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_calendar/chcontentCalendar.php?contentCalendar="+encodeURIComponent(str)+"&id="+id,true);
	
	xmlhttp.send();
}
</script>
<style>
<!--
* {padding:0; margin:0;}
-->
</style>

	<style type="text/css">
      div.item { padding-top: 5px;}
    </style>
    <link rel="stylesheet" href="content_calendar/stylesheets/jquery.tooltip/jquery.tooltip.css" type="text/css" />
    <script type="text/javascript" src="content_calendar/javascripts/jquery.min.js"></script>
    <script type="text/javascript" src="content_calendar/javascripts/jquery.tooltip.js"></script>
    <script type="text/javascript">
      $j = jQuery.noConflict();
      $j(document).ready(function(){
        $j("div.item").tooltip();
      });
    </script>
    
    
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<link rel="stylesheet" type="text/css" href="admin/css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script language="javascript" src="js/cal2.js"></script>
<style type="text/css">
.content_menu_expand{
	position:absolute; 
	right:-5px;
	top:20px;
	z-index:999;
	background-color: #ffffff;
	-moz-border-radius: 7px;
	-webkit-border-radius: 7px;
	color: #000000;
	width:300px; 
	max-height:180px;
	overflow:auto;
}


.passul{padding-left:0; border:1px solid black}
.bgkhac {background: #eee;}
.passul ul{padding:0px}
.passul ul li {color:#474747; font-size:12px;padding: 5px 0;padding-left:5px;list-style: none;}
.passul ul li:hover { background: #0A246A;color:white;text-decoration: none;list-style: none;}


</style>
<style type="text/css">
body{padding:0px; margin:0px}
.table{ width:715px; height:570px; margin:auto; }
table > tr {}
.table td {width:97px; height:50px; text-align:left;  }
.content { width:740px;padding-bottom: 10px;border-radius: 10px; border-radius: 10px; box-shadow:2px 2px 4px; background:#357cb0}
.content p { font-size:12px;left:2px;width:14px}
.ngaytruoc { color:#dbd1c7; }
.ngayhientai { background:#bf2400; border:#006; border-radius: 3px; padding:0px 8px ; color:#FFF}
.ngay { color:#656564;}
.sukien{  padding-top:15px;color:#ab044b;}
.sukien1 {background:#e1fcd0; color:#ab044b;font-size: 11px;}
.chunhat{ color:#c62a00;}
.container{font-family:Arial, Helvetica, sans-serif}
</style>


<div id="contains" style="height:100%;">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?=$l_work_calendar;?></div>
	<div class="content_code" style="height:100%;">
		<div class="approval-right" style="padding-right:10px; height:100%;">

<form action="calendar.php" method="post" name="frm1" id="f_ac_elisoft_order_tax" style="padding-left: 4px;">
			<table border="0" class="ftable1" cellspacing="0" style="background: rgb(92, 165, 206);padding: 3px 5px;">
		    	<tr>
		        	<th style="height:30px;width: 70px"><?php echo $l_month;?></th>
		            <th style="height:30px;">
		            	<select onchange="document.frm1.submit()" style="width:50px;height:24px;font-size:12px;text-align:center;valign:middle;" id="months" name="months">
							<?php for($i=1;$i<=12;$i++){?>
								<option value="<?=$i?>"  
									<?php 
										if($month==$i){
											?>
											selected="selected"
											<?php 
										}
									?>
								>
									<?php echo $i?>
								</option>
							<?php }?>
						</select> 
		            </th>
		            <th style="height:30px;width: 70px"><?php echo $l_year;?></th>
		            <th style="height:30px;">
		            	<select onchange="document.frm1.submit()" style="width:60px;height:24px;font-size:12px;text-align:center;valign:middle;" id="years" name="years">
							<?php for($i=2012;$i<=$vyear;$i++){?>
								<option value="<?=$i?>"  
									<?php 
										if($year==$i){
											?>
											selected="selected"
											<?php 
										}
									?>
								>
									<?php echo $i?>
								</option>
							<?php }?>
						</select> 
		            </th>
		        </tr>
		    </table>
		    </form>
			<table style="min-width: 1000px">

<tr>
	<td style="vertical-align: top;min-width: 300px;width: 500px">
			<input style="margin:12px 5px 0 0; font-size: 12px;" type="button" onclick="popup_window_show('#sample1', { pos : 'window-center', width : '640px', height:'800px'});" name="all" value="<?=$l_setting?>" class="btn_choose" />
		<p style="padding-top: 10px;"><?=$l_work_calendar;?></p>
						<table cellpadding="0" cellspacing="1" border="0" class="ftable1"  style="margin-top: 5px">
			<tr align='center'>
				<th style="width:30px;"><?=$l_no?></th>
				<th style="width:300px;"><?=$l_name_calendar;?></th>
				<th style="width:100px;"><?=$l_date;?></th>
			</tr>
							
							<?php  
							$k=1;
							foreach ($mang as $value => $giatri){
								if($giatri[3]==0){
								?>
							<tr>
								<td class="tdfirst" style="width:30px;"><?=$k?></td>
								<td class="tdfirst" style="text-align: left;width: 300px"><?php echo $giatri[1];?></td>
								<td ><input type="text" value="<?php echo $giatri['2'];?>" class="in_testfield" style="width:100px;float:left;height:24px;text-align: center; padding-right: 5px" readonly="readonly" disabled="disabled" /></td>
								
							</tr>
							
							<?php 
							$k++;
								}
							}if($k==1){?>
							<tr>
								<td class="tdfirst" colspan="3"><?=$l_list_emplty?></td>
								
							</tr>
							<?php }?>
						</table>
		
		<br>
	</td>
<td style="min-width: 700px;padding-left: 5px;vertical-align: top;">
<div class="container">
  <div class="content">
  <div style="text-align:center; text-transform:uppercase; padding:10px ">
  <a href="calendar.php?prev=on&months=<?=$month?>&years=<?=$year?>"><img src="images/left.png" style="margin: 10px 10px -5px;" /></a>
  <span style=" color:#FFF" ><? echo $months[$month-1]." ".$year;?></span>
  <a href="calendar.php?next=on&months=<?=$month?>&years=<?=$year?>"><img src="images/right.png" style="margin: 10px 0 -5px 10px;"  /></a>
  </div>
<table class="table" border="2px" bordercolor="#cac6c0" frame="void" cellpadding="0" cellspacing="0" style="border-radius: 10px; background:#FFF;">
	<tr >
	<?php
	$i=1;
	foreach($days as $day){
		if($i==1){
	?>
		<td style="border-top-left-radius:10px; background:#f1e8df; text-align:center;color:#c62a00;text-transform: uppercase;">
		<?php }else if($i==7){?>
		<td style="border-top-right-radius:10px; background:#f1e8df; text-align:center;text-transform: uppercase;">
			<?php }else{?>
		<td style="background:#f1e8df; text-align:center;text-transform: uppercase;">
		<?php }?>
			<div align="center"><b><?echo $day;?></b></div>
		</td>
	<?php 
	$i++;
	}?>
<?php 
for( $count=0;$count<(6*7);$count++){
	$dayarray = getdate($start);
	if((($count) % 7) == 0){
		if($dayarray['mon'] != $month)
		break;
		echo "</tr><tr style='height: 100px;'>";
	}
	if($count < $firstdayarray['wday'] || $dayarray['mon'] != $month){
		//if($count!=0)
			echo "<td></td>";
		//else 
		//	echo "<td bgcolor='#FFCC99' bordercolor='#FFCC99' style='width: 100px;'><br></td>";
	}
	else
	{
	$i=0;
	$sukien="";
	//$sukien.='<p class="sukien">';
	
	foreach ($mang as $value => $giatri){
		if($giatri[3]==0){
			$d=$giatri[2];
			
			if($dayarray['mday'] == date('d',strtotime($d))){
				
				$str='<div class="tooltip_description" style="display:none" title="">';
				$str.='<span>_ '.$giatri[1].' : <textarea style="width: 220px;resize: none;height:100px;" data-role="none">'.$giatri[4].'</textarea></span><br>';
				$sukien.='<div id="item_2" class="item"><span>☞ '.$giatri[1].'</span><br>';
			  	$sukien.=$str.'</div></div>';
			  
			
				$i++;
			}
			
		}
			
	}	
	//$sukien.= '</p>';
	if($dayarray['mday'] == $datearray['mday'] && $dayarray['mon'] == $datearray['mon'] && $dayarray['year']== $datearray['year']){	
?>
			<td <?php if($i!=0)echo "class='sukien1'";?>  ondblclick="LoadCalendar('<?php echo $dayarray['year'].'-'.$dayarray['mon'].'-'.$dayarray['mday'];?>');">
			<div style="height: 97px;">
            	<p class="ngayhientai" >
            	
<?php }else{?>
			<td <?php if($i!=0)echo "class='sukien1'";?> ondblclick="LoadCalendar('<?php echo $dayarray['year'].'-'.$dayarray['mon'].'-'.$dayarray['mday'];?>');">
			<div style="height: 97px;">
                <p <?php if($dayarray['wday']==0) echo 'class="chunhat"'; else echo 'class="ngay"'; ?> >
                
<?php }
		$str=$dayarray['mday'];
		echo $str;
		echo $sukien;
		
?>
</p>
</div>

			</td>
			
		<?php
		$start += ADAY;
		//}
	}
}
?>
</table>
    </div>
  </div>
</td>
</tr>
</table>	
			
			
		</div>
		

		
		
	</div>
	
	
</div>
<?php mysql_close($connection);?>